package com.umerclass.ui.home;

import android.view.Window;
import android.view.WindowManager;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import com.bumptech.glide.Glide;
import com.google.android.material.tabs.TabLayout;
import com.umerclass.R;
import com.umerclass.frame.model.InfoResult;
import com.umerclass.frame.ui.activity.BaseActivity;
import com.umerclass.ui.anmo.adapter.MyFragmentPagerAdapter;
import com.umerclass.ui.home.customer.MyJzvdStd;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import cn.jzvd.Jzvd;

/**
 * 视频
 */
public class VideoDetailsActivity extends BaseActivity {

    @BindView(R.id.tab)
    TabLayout tab;
    @BindView(R.id.viewpager)
    ViewPager viewpager;
    @BindView(R.id.jz_video)
    MyJzvdStd jzVideo;
    private List<String> titles = new ArrayList<>();
    private MyFragmentPagerAdapter myFragmentPagerAdapter;
    private ArrayList<Fragment> fragments = new ArrayList<>();

    @Override
    public boolean isImmersionBarEnabled() {
        return false;
    }

    @Override
    public boolean isSupportSwipeBack() {
        return false;
    }

    @Override
    public int getLayoutResId() {
        return R.layout.activity_video_details;
    }

    @Override
    public void init() {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(getResources().getColor(R.color.white));

        titles.add("课程详情");
        titles.add("课程目录");
        tab.addTab(tab.newTab().setText("课程详情"));
        tab.addTab(tab.newTab().setText("课程目录"));
        fragments.add(ClassDetailsFragment.newInstance());
        fragments.add(ClassDirFragment.newInstance());
        myFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager());
        myFragmentPagerAdapter.setFragments(fragments);
        myFragmentPagerAdapter.setTitles(titles);
        viewpager.setAdapter(myFragmentPagerAdapter);
        tab.setupWithViewPager(viewpager);
        viewpager.setOffscreenPageLimit(2);
        jzVideo.setUp("http://jzvd.nathen.cn/c6e3dc12a1154626b3476d9bf3bd7266/6b56c5f0dc31428083757a45764763b0-5287d2089db37e62345123a1be272f8b.mp4"
                , "饺子快长大");
        Glide.with(this).load("http://jzvd-pic.nathen.cn/jzvd-pic/1bb2ebbe-140d-4e2e-abd2-9e7e564f71ac.png")
                .into(jzVideo.posterImageView);
    }

    @Override
    public void loadData() {

    }

    @Override
    protected void onSuccess(int what, InfoResult t) {

    }

    @Override
    protected void onFail(int what, InfoResult t) {

    }

    @Override
    public void onBackPressed() {
        if (Jzvd.backPress()) {
            return;
        }
        super.onBackPressed();
    }

    @Override
    protected void onPause() {
        super.onPause();
        Jzvd.releaseAllVideos();
    }
}
